package org.kukker.activity.widget;

import org.kukker.R;
import java.util.Map;

import org.kukker.app.KukkerApp;
import org.kukker.event.Event;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class KukkerButton extends Button{
	public String debugtag="eventflow1";
	public KukkerButton(Context context, AttributeSet attrs, Map inflateParams) {
		  super(context, attrs, inflateParams);
		  this.init();
	}
	
	public boolean onTouchEvent(MotionEvent event){
		boolean res = super.onTouchEvent(event);
		String actionName = org.kukker.Util.kMotionEvent.getActionName(event);
		 Log.i(debugtag,
	    			"["+this.getClass().getSimpleName()+"]" +
	    			
	    			"["+
	    			"isSelected:"+this.isSelected()+
	    			"]"
	    			
	    			+"["
	    			+"onTouchEvent()"
	    			
	    			+", action:"+actionName
	    			+"]"
	    			
			 );
    			
		 
    	
		return res;
	}
	
	
	public boolean onKeyUp(int keyCode, KeyEvent event){
		boolean res = super.onKeyUp(keyCode, event);
		Log.i(debugtag,
    			"["+this.getClass().getSimpleName()+"]" +
    			
    			"["+
    			"isSelected:"+this.isSelected()+
    			"]"
    			
    			+"["
    			+"onKeyUp() " +
    			",keyCode:"+keyCode
    			
    			+"]"    			
    	);
		
		
		return res;
	}
	
	public boolean onKeyDown(int keyCode, KeyEvent event){
		boolean res = super.onKeyDown(keyCode, event);
		Log.i(debugtag,
    			"["+this.getClass().getSimpleName()+"]" +
    			
    			"["+
    			"isSelected:"+this.isSelected()+
    			"]"
    			
    			+"["
    			+"onKeyDown() " +
    			",keyCode:"+keyCode
    			
    			+"]"    			
    	);
	
		return res;
	}
	
	 public void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect){
		 super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
		  	Log.i(debugtag,

				"[" + this.getClass().getSimpleName() + "]" +

				"[" + "isSelected:" + this.isSelected() + "]"

				+ "[" + "onFocusChanged()" + ", gainFocus:" + gainFocus
						+ ", direction:" + direction + "]"

				);
				
		  	if(gainFocus){
		  		this.setBackground(R.drawable.orangebutton_alpha);
		  //	this.setSelected(true);
		  	//	this.requestFocus();
		  	}else{
		  		this.setBackground(R.drawable.greybutton_alpha);
		  		//this.setSelected(false);
		  		//this.clearFocus();
		  	}
	}
	 
	private int mEditableAreaWidth;
	private int mLabelAreaWidth;
	public final static int mWidth = 100;
	
	private void init(){
		this.setTextColor(Color.BLACK);		
		this.setFocusableInTouchMode(true);
		this.setClickable(true);
		this.setFocusable(true);
	}
}